package com.xingkeduo.business.operation.domain;

import com.xingkeduo.business.operation.service.BoardService;
import com.xingkeduo.pojo.query.BoardQuery;
import com.xingkeduo.pojo.table.BoardTable;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.pojo.enums.YesNoEnum;
import com.xingkeduo.util.pojo.exception.DataException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 商户domain
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class BoardDomain {
//    @Value("web.page.size")
//    private Integer pageSize;

    @Autowired
    private BoardService boardService;

    public BoardTable getBoardByCode(Long code) throws Throwable {
        BoardTable boardTable = boardService.selectByCode(code);
        return boardTable;
    }
    //分页
    public Page<BoardTable> getBoardList(BoardQuery boardQuery, Integer pageNum) throws Throwable {
        Page<BoardTable> boardList = boardService.selectLists(boardQuery,pageNum,2);
        return boardList;
    }

    public int createBoard(BoardTable boardTable) throws Throwable {
        return boardService.insert(boardTable);
    }

    public int modifyBoard(BoardTable boardTable) throws Throwable {
        return boardService.update(boardTable);
    }

    //删除
    public int delBoard(Long id) throws Throwable {
        BoardTable boardTable = new BoardTable();

        boardTable.setId(id);
        boardTable.setIsDelete(YesNoEnum.YES);
        int delRes = boardService.delete(boardTable);
        if(delRes > 0){
            return delRes;
        }else{
            throw new DataException(DataException.Type.FAIL, "删除失败");
        }
    }
}
